#include "usermanager.h"

namespace WordMemory
{
    UserManager::UserManager()
        : QObject(nullptr)
        , loggedIn(false)
    {
    }

    void UserManager::setCurrentUser(const User &user)
    {
        currentUser = user;
        loggedIn = true;
        emit userChanged(currentUser);
    }

    User UserManager::getCurrentUser() const
    {
        return currentUser;
    }

    int UserManager::getUserId() const
    {
        return currentUser._id;
    }

    QString UserManager::getUsername() const
    {
        return currentUser._username;
    }

    QString UserManager::getRealName() const
    {
        return currentUser._realName;
    }

    QString UserManager::getCreatedAt() const
    {
        return currentUser._createdAt;
    }

    bool UserManager::isLoggedIn() const
    {
        return loggedIn;
    }

    void UserManager::clearUser()
    {
        currentUser = User();
        loggedIn = false;
        emit userCleared();
    }
}
